/**
    File        : CSplashScreen.cpp
    Description : Splash Screen
    Author      : Raymond Marsh
    Created     : 08/01/2009
    Copyright 2009, 2010, 2011, 2012 Raymond Marsh

    This program is distributed under the terms of the GNU General Public License.
    To view a copy of the license see the file 'copying.txt'

    This file is part of the MyMoney Suite.

    MyMoney is free software: you can redistribute it and/or modify it under
    the terms of the GNU General Public License as published by the Free Software Foundation, either
    version 3 of the License, or (at your option) any later version.

    MyMoney is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along with MyMoney.
    If not, see <http://www.gnu.org/licenses/>.
**/

#include "..\include\SplashScreen.h"

BEGIN_EVENT_TABLE(CSplashScreen,wxDialog)
	EVT_PAINT (CSplashScreen::OnPaint)
END_EVENT_TABLE()

CSplashScreen::CSplashScreen(wxWindow* parent, const int Time, wxString FileName, wxString* Version, wxString* Revision)
: wxDialog(parent, wxID_ANY, "", wxDefaultPosition, wxSize(650, 300), wxSTAY_ON_TOP | wxNO_BORDER),
  m_pTimer(NULL), m_StatusMsg(wxEmptyString), m_Time(Time), m_FileName(FileName)
{
	if (Version != NULL)
        m_Version = *Version;
    else
        m_Version = wxEmptyString;
    if (Revision != NULL)
        m_Revision = *Revision;
    else
        m_Revision = wxEmptyString;

	m_Bitmap.LoadFile(m_FileName, wxBITMAP_TYPE_PNG);
    if (!m_Bitmap.IsOk() )
        mmErrorDlg(this, "Could not load Bitmap!");

	if(m_Time > 0)
        m_pTimer = new wxTimer(this);
}

CSplashScreen::~CSplashScreen()
{
    if (m_pTimer)
    {
        if (m_pTimer->IsRunning() )
            m_pTimer->Stop();
        delete m_pTimer;
    }
}

void CSplashScreen::Start()
{
    this->Show(true);
    if (m_pTimer)
        if(!m_pTimer->Start(m_Time, true) )
            mmErrorDlg(this, "Could not start timer!");
}

void CSplashScreen::Stop()
{
    if (m_pTimer)
        if (m_pTimer->IsRunning() )
            m_pTimer->Stop();
    this->Show(false);
}

void CSplashScreen::SetStatusMsg(const wxString text)
{
    m_StatusMsg = text;
    this->Refresh();
}

void CSplashScreen::OnPaint(wxPaintEvent& paint_event)
{
    wxPaintDC DC(this);
    if (!DC.IsOk() )
    {
        mmErrorDlg(this, "Bad DC!");
        return;
    }

    // draw bitmap
    DC.DrawBitmap(m_Bitmap, 0, 0);

    // draw version info
    DC.SetTextForeground(wxColor(0, 0, 0) );
    DC.SetFont(wxFont(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL) );
    if (m_Version != wxEmptyString)
        DC.DrawText(m_Version, 440, 180);
    if (m_Revision != wxEmptyString)
        DC.DrawText(m_Revision, 440, 200);

    // draw status line
    DC.SetFont(wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD) );
    if (m_StatusMsg != wxEmptyString)
        DC.DrawText(m_StatusMsg, 420, 230);
}
